home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / misc / ispell31.lha / ispell-3.1.18src / sq.c < prev    next >
C/C++ Source or Header  |  1994-01-25  |  4KB  |  110 lines

  1. #ifndef lint
  2. static char Rcs_Id[] =
  3.     "$Id: sq.c,v 1.12 1994/01/25 07:12:09 geoff Exp $";
  4. #endif
  5.  
  6. /*
  7.  * Copyright 1993, Geoff Kuenning, Granada Hills, CA
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  *
  14.  * 1. Redistributions of source code must retain the above copyright
  15.  *    notice, this list of conditions and the following disclaimer.
  16.  * 2. Redistributions in binary form must reproduce the above copyright
  17.  *    notice, this list of conditions and the following disclaimer in the
  18.  *    documentation and/or other materials provided with the distribution.
  19.  * 3. All modifications to the source code must be clearly marked as
  20.  *    such.  Binary redistributions based on modified source code
  21.  *    must be clearly marked as modified versions in the documentation
  22.  *    and/or other materials provided with the distribution.
  23.  * 4. All advertising materials mentioning features or use of this software
  24.  *    must display the following acknowledgment:
  25.  *      This product includes software developed by Geoff Kuenning and
  26.  *      other unpaid contributors.
  27.  * 5. The name of Geoff Kuenning may not be used to endorse or promote
  28.  *    products derived from this software without specific prior
  29.  *    written permission.
  30.  *
  31.  * THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
  32.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34.  * ARE DISCLAIMED.  IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
  35.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  39.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  40.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  41.  * SUCH DAMAGE.
  42.  */
  43.  
  44. /*
  45.  * $Log: sq.c,v $
  46.  * Revision 1.12  1994/01/25  07:12:09  geoff
  47.  * Get rid of all old RCS log lines in preparation for the 3.1 release.
  48.  *
  49.  */
  50.  
  51. #include <stdio.h>
  52.  
  53. #ifdef __STDC__
  54. #define P(x)    x
  55. #else /* __STDC__ */
  56. #define P(x)    ()
  57. #endif /* __STDC__ */
  58.  
  59. int        main P ((int argc, char * argv[]));
  60. static void    trunc P ((char * word, char * prev));
  61.  
  62. /*
  63.  * The following table encodes prefix sizes as a single character.  A
  64.  * matching table will be found in unsq.c.
  65.  */
  66. static char size_encodings[] =
  67.     {
  68.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',    /* 00-09 */
  69.     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',    /* 10-19 */
  70.     'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',    /* 20-29 */
  71.     'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',    /* 30-39 */
  72.     'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',    /* 40-49 */
  73.     'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',    /* 50-59 */
  74.     'y', 'z'                        /* 60-61 */
  75.     };
  76.  
  77. #define MAX_PREFIX    (sizeof (size_encodings) - 1)
  78.  
  79. int main (argc, argv)
  80.     int        argc;
  81.     char *    argv[];
  82.     {
  83.     char    word[257];
  84.     static char    prev[257] = "";
  85.  
  86.     while (gets (word) != NULL)
  87.     trunc (word, prev);
  88.     return 0;
  89.     }
  90.  
  91. static void trunc (word, prev) 
  92.     char *        word;
  93.     char *        prev;
  94.     {
  95.     register char *    wordp;
  96.     register char *    prevp;
  97.     register int    same_count;
  98.  
  99.     wordp = word;
  100.     prevp = prev;
  101.     for (same_count = 0;  *wordp == *prevp++;  ++wordp, ++same_count)
  102.     ;
  103.     if (same_count>MAX_PREFIX)
  104.     same_count = MAX_PREFIX;
  105.     (void) putchar (size_encodings[same_count]);
  106.     (void) puts (wordp);
  107.     (void) strcpy (prev, word);
  108.     }
  109.  
  110.